﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class OnllyPage5UIController : MonoBehaviour {

    public static OnllyPage5UIController Instance;
    public Transform tf_result;
    public Transform tf_right;

	// Use this for initialization
	void Start () {
        Instance = this;
        EventManager<bool>.AddEvent(MyEventType.OnllyResultEvent,ResultUI);
    }

    /// <summary>
    /// 结果界面的数值
    /// </summary>
    /// <param name="active"></param>
    private void ResultUI(bool active)
    {
        System.Random ran = new System.Random();
        string s0 = ShijianJiluUIController._instance.tf_IduanDongzuo.GetChild(0).GetComponent<Text>().text.Substring(0, 5);
        tf_result.Find("0").GetComponent<Text>().text = s0 + "A";
        tf_result.Find("1").GetComponent<Text>().text = (float.Parse(ShijianJiluUIController._instance.tf_IduanDongzuo.GetChild(1).GetComponent<Text>().text.Substring(0, 5)) * 1000).ToString("0.0")+"MS";
        tf_result.Find("3").GetComponent<Text>().text=ran.Next(2000,3000).ToString("0.0")+"MS";
        float s4 = ran.Next(800, 1000) / 1000.0f;
        tf_result.Find("4").GetComponent<Text>().text = s4.ToString("0.000");
        if (float.Parse(s0) * s4 >= 10) {
            tf_result.Find("2").GetComponent<Text>().text = (float.Parse(s0) * s4).ToString("0.00") + "A";
        }else
            tf_result.Find("2").GetComponent<Text>().text=(float.Parse( s0 )* s4).ToString("0.000") + "A";
        tf_right.Find("dongzuozhi").GetComponent<Text>().text= tf_result.Find("0").GetComponent<Text>().text;
        tf_right.Find("fanhuizhi").GetComponent<Text>().text = tf_result.Find("2").GetComponent<Text>().text;
        tf_right.Find("fanhuixishu").GetComponent<Text>().text = tf_result.Find("4").GetComponent<Text>().text;
        //tf_result.Find("00").GetComponent<Text>().text = tf_result.Find("0").GetComponent<Text>().text;
        //tf_result.Find("22").GetComponent<Text>().text = tf_result.Find("2").GetComponent<Text>().text;
        //tf_result.Find("44").GetComponent<Text>().text = tf_result.Find("4").GetComponent<Text>().text;
    }

    /// <summary>
    /// 清除结果左上角的数据
    /// </summary>
    public void ClearJieGuo() {
        for (int i = 0; i <= 4; i++) {
            tf_result.Find(i.ToString()).GetComponent<Text>().text = "";
        }
    }

    private bool isDayuTen(float num)
    {
        if (num >= 10.0f)
        {
            return true;
        }
        return false;
    }
}
